package com.net.xpay.web.controller.merchant.flexible;

import com.net.common.model.ResultData;
import com.net.common.util.SerializationUtil;
import com.net.xpay.common.domain.FlexibleStaffCard;
import com.net.xpay.common.domain.User;
import com.net.xpay.core.dto.ApplyFlexibleStaffCardDto;
import com.net.xpay.core.helper.SignerCheckHelper;
import com.net.xpay.core.model.ApplyFlexibleStaffCardModel;
import com.net.xpay.core.service.safePay.FlexibleStaffCardService;
import com.net.xpay.web.secutiry.RequestUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

@Controller
@Slf4j
@RequestMapping("/merchant/flexible-staff-card")
@Api(tags = "商户/灵工卡", description = "商户 灵工卡 net")
public class FlexibleStaffCardController {

    @Autowired
    private FlexibleStaffCardService flexibleStaffCardService;

    @Autowired
    private SignerCheckHelper signerCheckHelper;




    /**
     * 签约，获取签约链接
     */
    @ApiOperation(value = "灵工卡开卡签约，获取签约链接")
    @PostMapping("/sign")
    @ResponseBody
    public ResultData<ApplyFlexibleStaffCardDto> getFlexibleStaffCardSignPage(@ApiIgnore @RequestUser User merchant, @RequestBody ApplyFlexibleStaffCardModel model)  {
        log.info("getFlexibleStaffCardSignPage|params={}", SerializationUtil.obj2String(model));
        User user = signerCheckHelper.checkSign(model);

        FlexibleStaffCard card = flexibleStaffCardService.applyFlexibleStaffCard(user, model);

        ApplyFlexibleStaffCardDto dto = new ApplyFlexibleStaffCardDto();
        dto.setApplyLink(card.getApplyLink());
        dto.setFlowToken(card.getFlowToken());
        return new ResultData<>(dto);
    }

}
